package behaviorType.state;

public class Context {
    private int num; // 0正常状态；-1饥饿状态；1吃饱状态

    private IState state;

    public void setNum(int num) {
        this.num = num;
    }

    public void add() {
        num++;
    }

    public void del() {
        num--;
    }

    /**
     * 状态的变化
     */
    public void judgeState() {
        if (num == 0)
            state = new NormalStateImpl();
        else if (num < 0)
            state = new HungryStateImpl();
        else
            state = new FullStateImpl();
    }

    public void stateInfo() {
        judgeState(); // 通过变量改变状态
        this.state.stateInfo();
    }
}
